package com.stmt.stmtdesktop.udp;

import java.net.InetAddress;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
import lombok.NonNull;

/**
 * @author liangbo
 */
public record DelayMessage(long time, String message) implements Delayed {

  @Override
  public long getDelay(@NonNull TimeUnit unit) {
    long t = time - System.currentTimeMillis();
    return TimeUnit.MILLISECONDS.toMillis(t);
  }

  @Override
  public int compareTo(@NonNull Delayed o) {
    DelayMessage item = (DelayMessage) o;
    long diff = this.time - item.time;
    if (diff <= 0) {
      return -1;
    } else {
      return 1;
    }
  }
}
